package com.rabbitmq.ChattingRoom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.ChattingRoom.service.UserRoomMappingService;
import com.rabbitmq.ChattingRoom.service.mapper.UserRoomMappingMapper;
import com.rabbitmq.ChattingRoom.util.Entity.User;
import com.rabbitmq.ChattingRoom.util.Entity.UserRoomMapping;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class UserRoomMappingServiceImpl implements UserRoomMappingService {

    @Autowired
    private UserRoomMappingMapper mappingMapper;

    @Override
    public Integer addUserRoomMapping(UserRoomMapping record) {
        return mappingMapper.insert(record);
    }

    @Override
    public Integer delUserRoomMapping(UserRoomMapping record) {
        QueryWrapper<UserRoomMapping> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(UserRoomMapping::getUserId,record.getUserId());
        queryWrapper.lambda().eq(UserRoomMapping::getRoomId,record.getRoomId());
        return mappingMapper.delete(queryWrapper);
    }

    @Override
    public Integer delInfoByRoom(Long roomId) {
        QueryWrapper<UserRoomMapping> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserRoomMapping::getRoomId,roomId);
        return mappingMapper.delete(queryWrapper);
    }

    @Override
    public boolean isExist(Long userId,Long roomId) {
        if (ObjectUtils.isEmpty(mappingMapper.isExist(userId,roomId))) {
            return false;
        }
        return true;
    }


}
